package edu.ucsd.cse222b.events;

import java.util.Comparator;
import java.util.PriorityQueue;

public class FlowEventQueue{

	private class FlowEventComparator implements Comparator<FlowEvent>{
		
		public FlowEventComparator(){
			super();
		}

		@Override
		public int compare(FlowEvent arg0, FlowEvent arg1) {
			if(arg0.getTimestamp()<arg1.getTimestamp()){
				return -1;
			}else if(arg0.getTimestamp()==arg1.getTimestamp()){
				return 0;
			}else{
				return 1;
			}
		}
		
	}
	
	private PriorityQueue<FlowEvent> events;
	
	public FlowEventQueue(int initSize){
		events=new PriorityQueue<FlowEvent>(initSize, new FlowEventComparator());
	}
	
	public PriorityQueue<FlowEvent> getEvents(){
		return events;
	}
	
	public void enqueEvent(FlowEvent event){
		events.add(event);
	}
	
	public FlowEvent dequeueEvent(){
		FlowEvent event=events.peek();
		if(event!=null){
			events.remove(event);
		}
		return event;
	}
	
	public FlowEvent peekEvent(){
		return events.peek();
	}

}
